﻿<Window x:Class="Wpf2.Views.FormEditImportOrder"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Hóa đơn lưu - Sửa hóa đơn nhập" Height="700" Width="auto" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <StackPanel Orientation="Vertical" Height="669" VerticalAlignment="Top" Background="#FF3C2AF9" >
        <Border Height="50" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="5,5,5,5">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Label Margin="0,0,10,0" Content="HÓA ĐƠN NHẬP" Target="{Binding ElementName=txtUserID}" Background="{x:Null}" Foreground="#FF1E1E1E" FontSize="30" FontWeight="Bold"/>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="_Mã nhân viên" Target="{Binding ElementName=txtUserID}" Background="#FF0050EF" Foreground="White"/>
                    <TextBox  Background="#FF0050EF" Padding="5" Margin="0,0,20,0" Height="30" Width="100" x:Name="txtUserID" Text="{Binding User.ID_USER, UpdateSourceTrigger=PropertyChanged}" Foreground="#FFFCFCFC" />
                </StackPanel>
                <StackPanel Margin="0,0,20,0" Width="120" Height="30" Orientation="Horizontal">
                    <Button x:Name="btnSaveAddInvetory"  Width="90" Background="#16499A" Command="{Binding SaveOrderCommand}">
                        <TextBlock Foreground="#FFFCFCFC"><Run Text="Lưu"/></TextBlock>
                    </Button>
                    <StackPanel Width="30" Height="30" Background="#FF0050EF">
                        <Image Source="/Wpf2;component/Images/Save.png" />
                    </StackPanel>
                </StackPanel>
                <StackPanel Margin="0,0,20,0" Width="120" Height="30" Orientation="Horizontal">
                    <Button x:Name="btnPrint"  Width="90" Background="#16499A" Command="{Binding PrintOrderCommand}">
                        <TextBlock Foreground="#FFFCFCFC"><Run Text="In"/></TextBlock>
                    </Button>
                    <StackPanel Width="30" Height="30" Background="#FF0050EF">
                        <Image Source="/Wpf2;component/Images/print.png" />
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </Border>
        <StackPanel Margin="5,0,0,0" Height="50">
            <StackPanel Margin="0,0,5,0" Orientation="Horizontal" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" DataContext="{Binding StoreInfo}">
                <Label Height="30" Content="Tên cửa hàng"></Label>
                <TextBox Name="txtStoreName" Text="{Binding StoreName, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" Width="131" Height="20" Margin="0,15" ></TextBox>
                <Label Height="30" Content="Địa chỉ" Margin="20,0,0,0"></Label>
                <TextBox Name="txtAddress" Width="125" Height="20" Text="{Binding Address, UpdateSourceTrigger=PropertyChanged}" Margin="0,15"></TextBox>
                <Label Height="30" Content="Di động" Margin="20,0,0,0"></Label>
                <TextBox Name="txtMobile" Width="84" Height="20" Text="{Binding Mobile, UpdateSourceTrigger=PropertyChanged}" Margin="0,15" ></TextBox>
                <Label Height="30" Content="Điện thoại" Margin="20,0,0,0"></Label>
                <TextBox Name="txtPhone" Width="119" Height="20" Text="{Binding Phone, UpdateSourceTrigger=PropertyChanged}" Margin="0,15"></TextBox>
            </StackPanel>
        </StackPanel>
        <DataGrid Grid.Row="0" x:Name="dtgInventory" ItemsSource="{Binding ListProducts}" Background="White" Height="459" AutoGenerateColumns="False" CanUserAddRows="False" Margin="5,0,5,0" AlternatingRowBackground="PaleTurquoise">
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <TextBlock  Width="20" Text="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}, Mode=FindAncestor}}"/>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>

            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Mã Sản Phẩm" Width="90">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                <TextBox Height="20" Width="150" TextChanged="TxtProductNameTextChanged" Text="{Binding ProductId,UpdateSourceTrigger=PropertyChanged}" LostFocus="TxtProductNameLostFocus" KeyDown="TxtProductNameKeydown" BorderThickness="0" Background="{x:Null}"/>
                                <ComboBox SelectionChanged="ComboBoxSelectionChanged" Visibility="Hidden"  IsTabStop="False" IsSynchronizedWithCurrentItem="True" ></ComboBox>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Width="150" Header="Tên Sản Phẩm" Binding="{Binding ProductName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" CanUserSort="False"/>

                <DataGridTextColumn Width="150" Header="Mô Tả" Binding="{Binding ProductDescription, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" CanUserSort="False"/>
                <!-- BeginRegion-->
                <!-- DataGird không thể sử dụng elementName => phải dùng Source-->
                <!-- hiện lỗi không sao! cứ bỏ qua-->
                <!-- Xử lý dạng Đá Hoa Cương (9/5/2014)-->
                <DataGridTemplateColumn Header="Dài" Width="80" IsReadOnly="True" CanUserSort="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ProductHeight, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment" TextChanged="txtDaiRong_textChanged"  BorderThickness="0"  Background="{x:Null}"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Rộng" Width="80" IsReadOnly="True" CanUserSort="False" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ProductWidth, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment" TextChanged="txtDaiRong_textChanged" BorderThickness="0" Background="{x:Null}"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <!-- EndRegion-->
                <DataGridTemplateColumn Header="Số Lượng">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding InventoryCount, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TxtInventoryCountPreviewTextInput" BorderThickness="0" TextChanged="TxtInventoryTextChanged" Background="{x:Null}"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <!-- Chức năng Đá Hoa Cương: thêm ngày (9/5/14)-->
                <DataGridTextColumn Header="M2" Binding="{Binding ProductM2, UpdateSourceTrigger=PropertyChanged}" Width="80" IsReadOnly="True" CanUserSort="False"/>
                <DataGridTextColumn Width="100" Header="Giá" Binding="{Binding CostPrice, UpdateSourceTrigger=PropertyChanged,StringFormat={}\{0:###\,##0\}}" IsReadOnly="True"  CanUserSort="False"/>
                <DataGridTextColumn Width="100" Header="Đơn Vị" Binding="{Binding UnitName, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" CanUserSort="False"/>
                <DataGridTextColumn Width="100" Header="Nhóm" Binding="{Binding CatalogName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False"  CanUserSort="False"/>
                <DataGridTextColumn Width="*" Header="Thành tiền" Binding="{Binding TotalInPayment, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:###\, ###\}}" IsReadOnly="False"  CanUserSort="False"/>

            </DataGrid.Columns>

        </DataGrid>
        <StackPanel  Height="36"  Margin="5" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" RenderTransformOrigin="0.5,0.5">
            <StackPanel Margin="5" Orientation="Horizontal" HorizontalAlignment="Right">
                <Label   Height="30" Margin="0,0,0,0" Content="Tổng cộng: " Foreground="White" Background="#FF0050EF"/>
                <TextBox  Padding="5" Height="30" Name="txtTotalPayment" IsEnabled="False" Text="{Binding TotalPayment, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:###\,##0\} VNĐ}" Width="120" Background="#FF0050EF" Foreground="#FFFCFCFC"></TextBox>
            </StackPanel>
            
        </StackPanel>
    </StackPanel>
</Window>
